﻿using System;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using DotNetNuke.Entities.Users;

using System.Collections.Generic;
using Triax.Modules.ThongKeATLD;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

 //List<Triax.Modules.ThongKeATLD.DonViHanhChinhInfo> idatas 


namespace Samples.AspNet
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    [System.Web.Services.WebMethod]
    public  DonViHanhChinhInfo[] GetCustomers(string country)
    {
        List<DonViHanhChinhInfo> customers = new List<DonViHanhChinhInfo>();
        ThongkeATLDController ctr = new ThongkeATLDController();
        customers = ctr.getComment(country);

        //string query = string.Format("SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle]," +
        //        "[City], [Phone] FROM [Customers] WHERE Country LIKE '%{0}%'", country);

        //using (SqlConnection con =
        //        new SqlConnection("your connection string"))
        //{
        //    using (SqlCommand cmd = new SqlCommand(query, con))
        //    {
        //        con.Open();
        //        SqlDataReader reader = cmd.ExecuteReader();

        //        while (reader.Read())
        //        {
        //            Customer customer = new Customer();
        //            customer.CustomerID = reader.GetString(0);
        //            customer.CompanyName = reader.GetString(1);
        //            customer.ContactName = reader.GetString(2);
        //            customer.ContactTitle = reader.GetString(3);
        //            customer.City = reader.GetString(4);
        //            customer.Phone = reader.GetString(5);
        //            customers.Add(customer);
        //        }
        //    }
        //}

        return customers.ToArray();
    }
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string SelectDetail(string strId)
    {
        string sJSON = "";
        List<DonViHanhChinhInfo> customers = new List<DonViHanhChinhInfo>();
        ThongkeATLDController ctr = new ThongkeATLDController();
        customers = ctr.getComment(strId);
        JsonSerializer serializer0 = new JsonSerializer();
        serializer0.Converters.Add(new JavaScriptDateTimeConverter());
        serializer0.NullValueHandling = NullValueHandling.Ignore;
        sJSON = JsonConvert.SerializeObject(customers);
        return sJSON;

    }

    [WebMethod]
    public string pritePage(string currentpage)
    {
      //  objTD.code = User;
      //  objTD.title = Content;
     //   objTD.temp_string1 = Time;
        List<DonViHanhChinhInfo> customers = new List<DonViHanhChinhInfo>();
        ThongkeATLDController ctr = new ThongkeATLDController();
        customers = ctr.getComment(currentpage);
        string res = "<table rules=\"rows\" id=\"datalistproduct\" class=\"hovertable\" style=\"background-color: White; border-color: Black; border-width: 1px; border-style: solid; font-family: Verdana; font-size: 10pt; width: 350px; border-collapse: collapse;\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\"> \n";
        res += "<thead>	<tr> <th scope=\"col\">User</th><th scope=\"col\">Content</th><th scope=\"col\">Time</th>	</tr></thead> \n";
        res += "<tbody>\n";
        res += "<tr>\n";
      



        for (int i = 0; i < customers.Count; i++)
        {

            DonViHanhChinhInfo p = customers[i];
            res += "<tr>\n";
            res += "<td>" + p.code.ToString() + "</td>";

            res += "<td>" + p.title + "</td>";

            res += "<td>"+ p.title + "</td>";
            res += "</tr>\n";

        }
        res += "</tbody>\n";
        res += "</table>\n";

        return res;

    }
    
}
}